package com.hmall.user.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmall.feign.dto.Address;
import com.hmall.user.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/address")
@RestController
public class AddressController {


    @Autowired(required = false)
    private IAddressService addressService;

    /**
     * 根据用户id查询所有地址信息
     *
     * @param userId
     * @return List<Address>
     */
    @GetMapping("/uid/{userId}")
    public List<Address> selectByUserId(@PathVariable Long userId) {
        return addressService.list(new QueryWrapper<Address>().eq("user_id", userId));
    }

    /**
     * 1
     * 根据addressId查询地址
     *
     * @param id
     * @return Address
     */
    @GetMapping("/{id}")
    public Address getAddressById(@PathVariable("id") Long id) {
        if (id == 59) {
            int i = 1 / 0;
        }
        return addressService.getById(id);
    }
}
